package Servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/login")
public class loginServlet extends HttpServlet {
    public  loginServlet(){
        System.out.println("实验化阶段");
    }



    @Override
    public void init(ServletConfig config) throws ServletException {
        System.out.println("初始状态");
    }

    @Override
    public void destroy(){
        System.out.println("销毁状态");
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("服务状态");
        //处理请求的代码
        request.setCharacterEncoding("utf-8");
        //设置相应的格式
        response.setContentType("text/html;charset=utf-8");
        //设置响应的编码格式
        response.setCharacterEncoding("utf-8");

        //创建一个PrintWriter对象 向页面输出内容
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("  <head><title>Servlet</title></head>");
        out.println("  <body>");
        out.println("你好，欢迎来到Servlet世界");
        out.println("  </body>");
        out.println("</html>");
        out.flush();//刷新
        out.close();//关闭

    }
}